home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wtj201.zip / KIYOOKA.ZIP / HEAPTEST.WMC < prev    next >
Text File  |  1992-10-23  |  14KB  |  473 lines

  1. //Filename: HEAPTEST.WMC                                    
  2. //"HEAPTEST" Generated by WindowsMAKER Professional         
  3. //Author: Gen Kiyooka                                       
  4.  
  5. //
  6. // This file is maintained by WindowsMAKER Professional.
  7. // As you make changes in your application using WindowsMAKER Professional 
  8. // this file is automatically updated therefore you never need to modify 
  9. // this file. Don't add code here.
  10. // This file contains the default functions for: drawing bitmaps and icons,
  11. // creating and registering the main window, handling the main menu.
  12. // If you wish to replace any of these functions do so in the .C file.
  13. // For more information see the section "How Code is Generated" in the 
  14. // documentation. 
  15.  
  16.  
  17.  
  18. //*************************************************************
  19. //               GLOBAL VARIABLES                              
  20. //*************************************************************
  21.  
  22. HBRUSH      hMBrush = 0;        // Handle to brush for main window       
  23. HINSTANCE   hInst   = 0;        // Handle to instance.                   
  24. HWND        MainhWnd= 0;        // Handle to main window.                
  25. HWND        hClient = 0;        // Handle to window in client area.      
  26. FARPROC     lpClient= 0L;       // Function for window in client area.   
  27.  
  28.     
  29. //*************************************************************
  30. //           PROCESSES KEYBOARD ACCELERATORS                   
  31. //           AND MODELESS DIALOG BOX KEY INPUT                 
  32. //*************************************************************
  33.     
  34. BOOL BLDKeyTranslation(MSG *pMsg)
  35.     {
  36.     // Translate keystrokes so client area works as a dialog box 
  37.     if (hClient && IsDialogMessage(hClient,pMsg))
  38.         return TRUE;
  39.     return FALSE;               // No special key input
  40.     }
  41.     
  42.     
  43. //*************************************************************
  44. //        CUSTOM MESSAGE PROCESSING FOR MAIN WINDOW            
  45. //*************************************************************
  46.  
  47. LONG FAR PASCAL BLDDefWindowProc(HWND hWnd, UINT message, UINT wParam, LONG lParam )
  48.     {
  49.  
  50.     switch (message)
  51.         {
  52.  
  53.     case WM_NCLBUTTONDOWN:
  54.         return BLD_WM_NCLBUTTONDOWNMsg(hWnd,message,wParam,lParam);
  55.         break;
  56.     case WM_CREATE:
  57.         MainhWnd=hWnd;
  58.         BLD_MainWinControlsClFunc(hWnd,message,wParam,lParam);
  59.         break;
  60.     case WM_SETFOCUS:
  61.         if (IsWindow(hClient))
  62.             SetFocus(hClient);
  63.         break;
  64.     case WM_NCDESTROY:
  65.         if (hMBrush)
  66.             {
  67.             SetClassWord(hWnd,GCW_HBRBACKGROUND,
  68.                          (WORD)GetStockObject(WHITE_BRUSH));
  69.             DeleteObject(hMBrush);
  70.             hMBrush=0;
  71.             }
  72.         break;
  73.       default:
  74.         // Pass on message for default processing by Windows   
  75.         return DefWindowProc(hWnd, message, wParam, lParam);
  76.         }
  77.     return FALSE;               // Returns FALSE if not processed by Windows 
  78.     }
  79.  
  80.  
  81.  
  82. //*************************************************************
  83. //           PROCESSES ALL MENU ITEM SELECTIONS                
  84. //*************************************************************
  85.  
  86. BOOL BLDMenuCommand(HWND hWnd, UINT message, UINT wParam, LONG lParam )
  87. {
  88.  
  89.     switch( LOWORD(wParam) )
  90.         {
  91.     
  92.         // Processing of linked menu items in menu: HEAPTEST  
  93.     
  94.     default:
  95.         return FALSE;           // Not processed by this function.
  96.         }
  97.     return TRUE;                // Processed by this function.
  98.     }
  99.  
  100.  
  101.  
  102.  
  103. //*************************************************************
  104. //    FUNCTIONS FOR INITIALIZATION AND EXIT OF APPLICATION     
  105. //*************************************************************
  106.  
  107. BOOL BLDInitApplication(HANDLE hInst, HANDLE hPrev, int *pCmdShow, LPSTR lpCmd)
  108.     {
  109.     // No initialization necessary 
  110.     return TRUE;
  111.     }
  112.  
  113.  
  114.  
  115. // Registers the class for the main window
  116. BOOL BLDRegisterClass( HANDLE hInstance )
  117.     {
  118.     WNDCLASS WndClass;
  119.  
  120.     hMBrush=0;
  121.  
  122.     WndClass.style         = 0;
  123.     WndClass.lpfnWndProc   = BLDMainWndProc;
  124.     WndClass.cbClsExtra    = 0;
  125.     WndClass.cbWndExtra    = 0;
  126.     WndClass.hInstance     = hInstance;
  127.     WndClass.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
  128.     WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  129.     WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  130.     WndClass.lpszMenuName  = NULL;
  131.     WndClass.lpszClassName = "HEAPTEST";
  132.  
  133.     return RegisterClass(&WndClass);
  134.     }
  135.  
  136.  
  137.  
  138.  
  139. HWND BLDCreateWindow( HANDLE hInstance )  // Creates the main window                 
  140. {
  141.     HWND hWnd;                  // window handle                           
  142.     int coordinate[4];          // Coordinates of main window              
  143.  
  144.     coordinate[0]=CW_USEDEFAULT;
  145.     coordinate[1]=0;
  146.     coordinate[2]=CW_USEDEFAULT;
  147.     coordinate[3]=0;
  148.  
  149.     hWnd = CreateWindow("HEAPTEST",  // window class registered earlier  
  150.            "Heap API Tester",          // window caption                           
  151.            WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX,               // window style    
  152.            coordinate[0],       // x position      
  153.            coordinate[1],       // y position      
  154.            coordinate[2],       // width           
  155.            coordinate[3],       // height          
  156.            0,                   // parent handle   
  157.            0,                   // menu or child ID
  158.            hInstance,           // instance        
  159.            (LPSTR)NULL);        // additional info 
  160.  
  161.     return hWnd;
  162.     }
  163.  
  164.  
  165.  
  166. // Called just before entering message loop 
  167. BOOL BLDInitMainMenu(HWND hWnd)
  168.     {
  169.     // No initialization necessary 
  170.     return TRUE;
  171.     }
  172.  
  173.  
  174.  
  175. BOOL BLDExitApplication()       // Called just before exit of application  
  176.     {
  177.     return TRUE;
  178.     }
  179.  
  180.  
  181.  
  182.  
  183. //********************************************************
  184. // ERROR MESSAGE HANDLING (Definitions can be overruled.) 
  185. //********************************************************
  186.  
  187. #ifndef ERRORCAPTION
  188. #define ERRORCAPTION "Heap API Tester"
  189. #endif
  190.  
  191. #ifndef LOADERROR
  192. #define LOADERROR "Cannot load string."
  193. #endif
  194.  
  195.  
  196. int BLDDisplayMessage(HWND hWnd, unsigned uMsg, char *pContext, int iType) 
  197.     {
  198.     int i, j; 
  199.     char Message[200+1]; 
  200.      
  201.     if (uMsg)
  202.         { 
  203.         if (!LoadString(hInst,uMsg,Message,200)) 
  204.             {
  205.             MessageBox(hWnd,LOADERROR,ERRORCAPTION, MB_OK|MB_SYSTEMMODAL|MB_ICONHAND); 
  206.             return FALSE; 
  207.             }
  208.         }
  209.     else
  210.         Message[0]=0;
  211.     
  212.     if (pContext) 
  213.         { 
  214.         i = lstrlen(Message); 
  215.         j = lstrlen(pContext); 
  216.         if (i + j + 1 <= 200) 
  217.             {
  218.             lstrcat(Message, " ");
  219.             lstrcat(Message, pContext);
  220.             }
  221.         }
  222.  
  223.     return MessageBox(hWnd,Message,ERRORCAPTION,iType); 
  224.     }
  225.  
  226.  
  227. //*************************************************************
  228. //         FUNCTIONS FOR DRAWING GRAPHIC BUTTONS               
  229. //*************************************************************
  230.  
  231. BOOL BLDDrawIcon(LPDRAWITEMSTRUCT lpDrawItem, char *pIconName)
  232.     {
  233.     HICON hIcon;
  234.  
  235.     hIcon = LoadIcon(hInst,pIconName);
  236.     if (!hIcon)
  237.         {
  238.         BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadIcon,pIconName, MB_OK | MB_ICONASTERISK);
  239.         return FALSE;
  240.         }
  241.     
  242.     SetMapMode(lpDrawItem->hDC,MM_TEXT);
  243.     return DrawIcon(lpDrawItem->hDC,0,0,hIcon);
  244.     }
  245.  
  246.  
  247. BOOL BLDDrawBitmap(LPDRAWITEMSTRUCT lpDrawItem, char *pBitmapName, BOOL bStretch)
  248.     {
  249.     HBITMAP hBitmap;
  250.     HDC hMemDC;
  251.     BITMAP Bitmap;
  252.     int iRaster;
  253.     
  254.     iRaster = GetDeviceCaps(lpDrawItem->hDC,RASTERCAPS);
  255.     if ((iRaster&RC_BITBLT)!=RC_BITBLT)
  256.         return FALSE;           // Device cannot display bitmap 
  257.     
  258.     hBitmap = LoadBitmap(hInst,pBitmapName);
  259.     if (!hBitmap)
  260.         {
  261.         BLDDisplayMessage(GetActiveWindow(),BLD_CannotLoadBitmap,pBitmapName,
  262.                           MB_OK | MB_ICONASTERISK);
  263.         return FALSE;
  264.         }
  265.     
  266.     if (!GetObject(hBitmap,sizeof(BITMAP),(LPSTR)&Bitmap))
  267.         {
  268.         DeleteObject(hBitmap);
  269.         return FALSE;
  270.         }
  271.     hMemDC = CreateCompatibleDC(lpDrawItem->hDC);
  272.     if (!hMemDC)
  273.         {
  274.         DeleteObject(hBitmap);
  275.         return FALSE;
  276.         }
  277.     if (!SelectObject(hMemDC,hBitmap))
  278.         {
  279.         DeleteDC(hMemDC);
  280.         DeleteObject(hBitmap);
  281.         return FALSE;
  282.         }
  283.     
  284.     if (bStretch)
  285.         {
  286.         StretchBlt(lpDrawItem->hDC,
  287.             lpDrawItem->rcItem.left,
  288.             lpDrawItem->rcItem.top,
  289.             lpDrawItem->rcItem.right-lpDrawItem->rcItem.left,
  290.             lpDrawItem->rcItem.bottom-lpDrawItem->rcItem.top,
  291.             hMemDC,
  292.             0,
  293.             0,
  294.             Bitmap.bmWidth,
  295.             Bitmap.bmHeight,
  296.             SRCCOPY);
  297.        }
  298.     else
  299.        {
  300.         BitBlt(lpDrawItem->hDC,
  301.             lpDrawItem->rcItem.left,
  302.             lpDrawItem->rcItem.top,
  303.             lpDrawItem->rcItem.right-lpDrawItem->rcItem.left,
  304.             lpDrawItem->rcItem.bottom-lpDrawItem->rcItem.top,
  305.             hMemDC,
  306.             0,
  307.             0,
  308.             SRCCOPY);
  309.        }
  310.     DeleteDC(hMemDC);
  311.     DeleteObject(hBitmap);
  312.     return TRUE;
  313.     }
  314.  
  315.  
  316.  
  317. //*************************************************************
  318. //       FUNCTION FOR CREATING CONTROLS IN MAIN WINDOW         
  319. //*************************************************************
  320.  
  321. // Startup procedure for window in client area 
  322. HWND BLDCreateClientControls(char *pTemplateName, FARPROC lpNew)
  323. {
  324.     RECT rClient,rMain,rDialog;
  325.     int dxDialog,dyDialog,dyExtra,dtXold,dtYold;
  326.     HANDLE hRes,hMem;
  327.     LPBLD_DLGTEMPLATE lpDlg;
  328.     unsigned long styleold,style;
  329.     HWND hNew;
  330.     
  331.     if (!IsWindow(MainhWnd))
  332.         return 0;
  333.     if (IsZoomed(MainhWnd))
  334.         ShowWindow(MainhWnd,SW_RESTORE);
  335.     
  336.     if (IsWindow(hClient))     
  337.          DestroyWindow(hClient); // Destroy Previous window in client area  
  338.     
  339.     // Get access to data structure of dialog box containing layout of controls 
  340.     hRes=FindResource(hInst,(LPSTR)pTemplateName,RT_DIALOG);
  341.     if (!hRes)
  342.         return 0;
  343.     hMem=LoadResource(hInst,hRes);
  344.     if (!hMem)
  345.         return 0;
  346.     lpDlg=(LPBLD_DLGTEMPLATE)LockResource(hMem);
  347.     if (!lpDlg)
  348.         return 0;
  349.     
  350.     // Change dialog box data structure so it can be used as a window in client area 
  351.     styleold        = lpDlg->dtStyle;
  352.     style           = lpDlg->dtStyle&(CLIENTSTRIP);
  353.     lpDlg->dtStyle  = lpDlg->dtStyle^style;
  354.     lpDlg->dtStyle  = lpDlg->dtStyle | WS_CHILD | WS_CLIPSIBLINGS;
  355.     dtXold          = lpDlg->dtX;
  356.     dtYold          = lpDlg->dtY;
  357.     lpDlg->dtX      = 0;
  358.     lpDlg->dtY      = 0;
  359.     
  360.     hNew = CreateDialogIndirect(hInst,(LPSTR)lpDlg, MainhWnd,lpNew);
  361.     if (!hNew)
  362.         return 0;
  363.     
  364.     // Restore dialog box data structure. 
  365.     lpDlg->dtStyle  = styleold;
  366.     lpDlg->dtX      = dtXold;
  367.     lpDlg->dtY      = dtYold;
  368.     
  369.     UnlockResource(hMem);
  370.     FreeResource(hMem);
  371.     
  372.     // Move and size window in client area and main window 
  373.     GetClientRect(MainhWnd,&rClient);
  374.     GetWindowRect(MainhWnd,&rMain);
  375.     GetWindowRect(hNew,&rDialog);
  376.     dxDialog=(rDialog.right-rDialog.left)-(rClient.right-rClient.left);
  377.     dyDialog=(rDialog.bottom-rDialog.top)-(rClient.bottom-rClient.top);
  378.     BLDMoveWindow(MainhWnd,rMain.left,rMain.top,
  379.                (rMain.right-rMain.left)+dxDialog,
  380.                   (rMain.bottom-rMain.top)+dyDialog,
  381.                  TRUE);
  382.     MoveWindow(hNew,0,0,
  383.                    (rDialog.right-rDialog.left),
  384.                    (rDialog.bottom-rDialog.top),
  385.                    TRUE);
  386.     GetClientRect(MainhWnd,&rClient);
  387.     
  388.     // Compensate size if menu bar is more than one line. 
  389.     if ((rDialog.bottom-rDialog.top)>(rClient.bottom-rClient.top))
  390.         {
  391.         dyExtra=(rDialog.bottom-rDialog.top)-(rClient.bottom-rClient.top);
  392.         BLDMoveWindow(MainhWnd,rMain.left,rMain.top,
  393.                    (rMain.right-rMain.left)+dxDialog,
  394.                    (rMain.bottom-rMain.top)+dyDialog+dyExtra,
  395.                    TRUE);
  396.         }
  397.     
  398.     ShowWindow(hNew,SW_SHOW);
  399.     hClient=hNew;
  400.     lpClient=lpNew;
  401.     return hClient;
  402.     }
  403.     
  404.     
  405. // Ensure that window is within screen. 
  406. void BLDMoveWindow(HWND hWnd, int x, int y,
  407.     int nWidth, int nHeight, BOOL bRepaint)
  408.     {
  409.     int xMax,yMax,xNew,yNew;
  410.     
  411.     xMax = GetSystemMetrics(SM_CXSCREEN);
  412.     yMax = GetSystemMetrics(SM_CYSCREEN);
  413.     
  414.     if ((nWidth<=xMax)&&(x+nWidth>xMax))
  415.         xNew=xMax-nWidth;
  416.     else
  417.         xNew=x;
  418.     
  419.     if ((nHeight<=yMax)&&(y+nHeight>yMax))
  420.         yNew=yMax-nHeight;
  421.     else
  422.         yNew=y;
  423.     
  424.     MoveWindow(hWnd,xNew,yNew,nWidth,nHeight,bRepaint);
  425.     return;
  426.     }
  427.     
  428.     
  429.     
  430.  
  431.  
  432.  
  433. //*************************************************************
  434. //       FUNCTION FOR SWITCHING MENU SET                       
  435. //*************************************************************
  436.  
  437. BOOL BLDSwitchMenu(HWND hWnd, char *pTemplateName)
  438.     {
  439.     HMENU hMenu1,hMenu;
  440.     DWORD style;
  441.     
  442.     style = GetWindowLong(hWnd,GWL_STYLE);
  443.     if((style & WS_CHILD) == WS_CHILD)     // Called from control in main window? 
  444.         {
  445.         hWnd=GetParent(hWnd);
  446.         if (!hWnd)
  447.             return FALSE;
  448.         style = GetWindowLong(hWnd,GWL_STYLE);
  449.         if((style & WS_CHILD) == WS_CHILD) // No menu in a WS_CHILD window.       
  450.             return FALSE;
  451.         }
  452.     if((style & WS_CAPTION) != WS_CAPTION) // No menu if no caption.              
  453.         return FALSE;
  454.     
  455.     hMenu1 = GetMenu(hWnd);
  456.     hMenu = LoadMenu(hInst,pTemplateName);
  457.     if (!hMenu)
  458.         {
  459.         BLDDisplayMessage(hWnd,BLD_CannotLoadMenu,pTemplateName,
  460.                           MB_OK | MB_ICONASTERISK);
  461.         return FALSE;
  462.         }
  463.     
  464.     if (!SetMenu(hWnd,hMenu))
  465.         return FALSE;
  466.     if (hMenu1)
  467.         DestroyMenu(hMenu1);
  468.     
  469.     DrawMenuBar(hWnd);
  470.     return TRUE;
  471.     }
  472.     
  473.